const express = require('express');
//导入小册的数据
const xiaoces = require('./xiaoce.json');

const app = express();
//设置
app.set('view engine','ejs');
app.set('views', __dirname + '/views');

app.get('/books', (request, response) => {
    response.render('xiaoce', {xiaoces});
});

//   /book/6844733769996304392
app.get('/book/:id', (request, response) => {
    //获取路由参数 id
    const id = request.params.id;
    //根据 id 参数获取小册的详细内容
    let result = xiaoces.data.find(item => {
        return item.booklet_id === id;
    });
    //响应结果
    response.render('detail', {book: result});
});

app.listen(80, () => {
    console.log('服务已经启动.....');
});